﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ImageRecognition2.Forms
{
    public partial class FormFilterPreferences : Form
    {
        public FormFilterPreferences()
        {
            InitializeComponent();

            chkbA.Checked = (bool)PrefsSingleton.Instance["A"];
            chkbR.Checked = (bool)PrefsSingleton.Instance["R"];
            chkbG.Checked = (bool)PrefsSingleton.Instance["G"];
            chkbB.Checked = (bool)PrefsSingleton.Instance["B"];
            chkbUseMask.Checked = (bool)PrefsSingleton.Instance["UseMask"];
        }

        private void cbOK_Click(object sender, EventArgs e)
        {
            PrefsSingleton.Instance.Values["A"] = chkbA.Checked;
            PrefsSingleton.Instance.Values["R"] = chkbR.Checked;
            PrefsSingleton.Instance.Values["G"]= chkbG.Checked;
            PrefsSingleton.Instance.Values["B"] = chkbB.Checked;
            PrefsSingleton.Instance.Values["UseMask"] = chkbUseMask.Checked;
        }

        private void cbAll_Click(object sender, EventArgs e)
        {
            SetAllChannels(true);
        }

        private void cbNone_Click(object sender, EventArgs e)
        {
            SetAllChannels(false);
        }

        private void InvertChannels()
        {
            chkbA.Checked = !chkbA.Checked;
            chkbR.Checked = !chkbR.Checked;
            chkbG.Checked = !chkbG.Checked;
            chkbG.Checked = !chkbG.Checked;
        }

        private void SetAllChannels(bool _bEnabled)
        {
            chkbA.Checked = _bEnabled;
            chkbR.Checked = _bEnabled;
            chkbG.Checked = _bEnabled;
            chkbB.Checked = _bEnabled;
        }

        private void cbInvert_Click(object sender, EventArgs e)
        {
            InvertChannels();
        }
    }

    public class Preferences
    {
        private Dictionary<string, object> m_aObject = new Dictionary<string, object>();
        
        private Preferences()
        {
            m_aObject.Add("R", false);
            m_aObject.Add("G", false);
            m_aObject.Add("B", false);
            m_aObject.Add("A", false);
            m_aObject.Add("UseMask", false);
        }

        public Dictionary<string, object> Values
        {
            get { return m_aObject; }
        }

        public object this[string _sValueName]
        {
            get { return m_aObject[_sValueName]; }
        }

        internal static Preferences Create()
        {
            return new Preferences();
        }
    }

    public class PrefsSingleton
    {
        private static Preferences staticPreferences = Preferences.Create();


        private PrefsSingleton()
        {
        }

        public static Preferences Instance
        {
            get { return staticPreferences; }
        }
    }
}
